package com.rxmvp.rxmvpdemo.base;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.rxmvp.rxmvpdemo.base.mvp.IBaseView;
import com.rxmvp.rxmvpdemo.utils.ToastUtil;
import com.trello.rxlifecycle.components.support.RxFragment;

import butterknife.ButterKnife;

/**
 * 在不使用presenter时，fragment可以直接继承该类，使用fragment的共有方法
 *
 * 作者： huangRZ on 2017/1/21. 15:43
 * 邮箱：917647409@qq.com
 */

public abstract class BaseFragment extends RxFragment implements IBaseView {

    protected View mRootView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        //缓存view对象
        if (mRootView == null) {
            mRootView = getRootView(inflater, container, savedInstanceState);
        }
        ButterKnife.bind(this, mRootView);
        return mRootView;
    }

    protected abstract View getRootView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState);

    @Override
    public void showShortToast(String msg) {
        ToastUtil.showToast(msg);
    }

    @Override
    public void showLongToast(String msg) {
        ToastUtil.showLongToast(msg);
    }

    @Override
    public void jump2activity(Class clazz){
        this.startActivity(new Intent(getActivity(), clazz));
    }

}
